using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Firestarter.DB.Schema.Logic;
using Habanero.Testability;
using NUnit.Framework;

namespace Firestarter.DB.Schema.Test.Logic
{
    [TestFixture]
    public class TestRegexBuilder
    {
        
        private static string GetRandomString()
        {
            return RandomValueGen.GetRandomString();
        }
        [Test]
        public void Test_Delimited_Match_WithZero_WhenZeroToOne_Passes()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 0, 1).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsTrue(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithOne_WhenZeroToOne_Passes()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("{0}", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 0, 1).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsTrue(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithTwo_WhenZeroToOne_Fails()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("{0},{0}", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 0, 1).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsFalse(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithZero_WhenOneToTwo_Fails()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 1, 2).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsFalse(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithOne_WhenOneToTwo_Passes()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("{0}", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 1, 2).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsTrue(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithTwo_WhenOneToTwo_Passes()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("{0},{0}", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 1, 2).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsTrue(Regex.IsMatch(sql, regex));
        }

        [Test]
        public void Test_Delimited_Match_WithThree_WhenOneToTwo_Fails()
        {
            //---------------Set up test pack-------------------
            RegexBuilder regexBuilderSQL = new RegexBuilder();
            string itemText = GetRandomString();
            string sql = string.Format("{0},{0},{0}", itemText);
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            string regex = regexBuilderSQL.StartText.Delimited(RegexBuilder.Create().Specific(itemText), ",", 1, 2).EndText.ToString();
            //---------------Test Result -----------------------
            Assert.IsFalse(Regex.IsMatch(sql, regex));
            
        }

    }
}
